package leetcode.editor.cn.q0xx

import leetcode.editor.cn.ListNode

/**
 * Example:
 * var li = ListNode(5)
 * var v = li.`val`
 * Definition for singly-linked list.
 * class ListNode(var `val`: Int) {
 *     var next: ListNode? = null
 * }
 */
class Q83 {

    fun deleteDuplicates(head: ListNode?): ListNode? {
        if (head == null) return null
        var first = head
        var cur = head
        while (cur != null) {
            if (first!!.`val` != cur.`val`) {
                first.next = cur
                first = cur
            }
            cur = cur.next
        }
        first!!.next = null
        return head
    }
}